package com.finals.media.service;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;

public class DownloadService extends Service {

	MusicePlayer musicePlayer;

	@Override
	public void onCreate() {
		super.onCreate();
		InitData();
	}

	private void InitData() {
		musicePlayer = new MusicePlayer(this);
	}

	@Override
	public int onStartCommand(Intent intent, int flags, int startId) {
		if (intent == null) {
			return 0;
		}
		int Action = intent.getIntExtra("Action", 0);
		switch (Action) {
		case 1:
			PlayMusic(intent);
			break;
		case 2:
			StopMusic();
			break;

		default:
			break;
		}
		return super.onStartCommand(intent, flags, startId);
	}

	private void PlayMusic(Intent intent) {
		String pathString = intent.getStringExtra("Path");
		musicePlayer.PlayMusic(pathString);
	}

	private void StopMusic() {
		musicePlayer.Pause();
	}

	@Override
	public IBinder onBind(Intent intent) {
		return null;
	}

	@Override
	public void onDestroy() {
		musicePlayer.onDestroy();
		super.onDestroy();
	}

}
